/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view.GUI.actions;

import controller.BidirectionalHashMap;
import controller.commands.ExecuteCommand;
import core.HighLightTracker;
import core.Tracker;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import load.util.Timer;
import model.graphic.GraphicModel;
import model.graphic.objects.GNode;
import model.graphic.objects.GTriggerPort;
import view.GUI.LabelReader;
import view.GUI.graphic.GraphicView;

/**
 *
 * @author Arfeniel
 */
public class DebugredAction extends AbstractAction{
    private GraphicModel gmodel;
    private GraphicView gview;
    private JTextArea debug;
 

    public DebugredAction(GraphicView gview, GraphicModel gmodel, JTextArea debug) {
        this.gview = gview;
        this.gmodel=gmodel;
        this.debug=debug;
    }
    public void actionPerformed(ActionEvent e) {
        BidirectionalHashMap sync = BidirectionalHashMap.getInstance();
        if(gmodel.isMainTriggerSet()){
            JTabbedPane tabUnder = (JTabbedPane) debug.getParent().getParent().getParent();
            tabUnder.setSelectedIndex(1);
            Tracker.setInstance(new HighLightTracker(gview, debug));
            if(Timer.class.isAssignableFrom(sync.get(((GNode)((GTriggerPort)gmodel.getMainTrigger().getBase()).getBase())).getClass())){
                JOptionPane.showMessageDialog(gview.getParent(), LabelReader.getInstance().getString("YouCanTDebugATimerSetAnotherMainTrigger"), LabelReader.getInstance().getString("Error"),JOptionPane.INFORMATION_MESSAGE);
            }else{
                gview.notifyObservers(new ExecuteCommand(gmodel.getMainTrigger()));
            }
        }else{
            JOptionPane.showMessageDialog(gview.getParent(), LabelReader.getInstance().getString("SetMainTriggerError"), LabelReader.getInstance().getString("Error"),JOptionPane.INFORMATION_MESSAGE);
        }
    }

}
